/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.netbeans.saas.facebook;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author balbir kaur
 */
public class FacebookSocialNetworkingServiceCallback extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            HttpSession session = request.getSession(true);
            String authToken = request.getParameter("auth_token");
            session.setAttribute("facebook_auth_token", authToken);
            
            FacebookSocialNetworkingServiceAuthenticator.login(request, response);
            String sessionKey = FacebookSocialNetworkingServiceAuthenticator.getSessionKey(request, response);
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Facebook Authorization Page</title>");
            out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
            out.println("<link href='include/quiz.css' rel='stylesheet' media='screen' type='text/css'/>");
            out.println("</head>");
            out.println("<body>");
            out.println("<div id='header'>");
            out.println("<h2><em>Counter Strike 1.6 Quiz</em></h2><br/>");
            out.println("<em>How well do you know cs1.6 </em>");
            out.println("</div>");
            out.println("<div id='allcontent'>");
            out.println("<div id='leftsidebar'>");
            out.println("</div>");
            out.println("<div id='main'>");
            out.println("<p>Looks like you already have a session key  " + sessionKey + "</p>");
            out.println("</div>");
            out.println("</div>");
            out.print("<div id='footer'>");
            out.println("<div align='right'>mail to:<a href='mailto:ramannanda9@gmail.com'><em> ramannanda9@gmail.com</em></a><br/>");
            out.println("<em>&copy;CS-QUIZ</em> developed by <em>Raman deep Singh</em><br/>CS-QUIZ Web App is powered by &dagger;<em>Struts2</em> Framework </div></div>");
            out.println("</body>");
            out.println("</html>");

        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
